<?php
$T->loadTpl("./html/".$template."/".$qname.".html");
$T->SetTpl('cssjs','html/cssjs.inc');
$T->SetTpl('jsmodel','html/jsmodel.inc');

if (empty($_SESSION['uid'])) {
    $tips = array(
        'tips' => '请登录后再进行操作',
        'url' => 'index.php'
    );
    $tips = urlencode(serialize($tips));
    header('Location:/tips.php?gets=' . $tips);
    exit;
}
$user_id = $_SESSION['uid'];

$service_sn=isset($_GET["service_sn"])?$_GET["service_sn"]:"";
$repair_status=isset($_GET["repair_status"])?$_GET["repair_status"]:"";
$p=isset($_GET["p"])?$_GET["p"]:"0";
$seach_where="";
if(!empty($service_sn)){
    $seach_where.=" and service_sn='".$service_sn."'";
}
if(!empty($repair_status)){
    $seach_where.=" and status=".$repair_status;
}
if($p<1)$p=1;
$rc=$T->db->query("select count(*) from sys_takes_list where id >0 and release_user_id='".$user_id."' and is_delete_false = 0 ".$seach_where)->fetchColumn(0);

$page=getPageHtml_bt($rc,15,$p,"&t=repair_mytakes&service_sn=".$service_sn."&repair_status=".$repair_status);
$page=mb_convert_encoding($page, 'utf-8', 'utf-8');
$status_html = "";
$html = '';
//                  0       1      2       3      4       5       6       7       8       9       10
$REPAIR_STATUS = ['全部','已申请','修复中','已维修','已结束','待评价','已评价','已撤回','待维修','已拒绝','无法处理'];
foreach($REPAIR_STATUS as $key=>$val){
    if($key == $repair_status){
        $status = "selected";
    }else{
        $status = "";
    }
    $status_html.="<option value='".$key."'".$status.">".$val."</option>";
}
$T->Set("status_html",$status_html);
$T->Set("is_list",$rc);
$T->Set("p",$p);
$T->Set("page",$page);
$T->Set("service_sn",$service_sn);

function Recombination($arr,$id='id',$name='name'){
    $newArr = array();
    foreach($arr as $val){
        $newArr[$val[$id]] = $val[$name];// = $val['id'];
    }
    return $newArr;
}
$sql = "select * from sys_takes_list where id >0 and release_user_id='".$user_id."' and is_delete_false = 0 ".$seach_where." order by id asc limit ".(($p-1)*15).",15";
$user_list = $T->db->query("select id,truename from sys_member")->fetchAll(PDO::FETCH_ASSOC);
$userlist =  Recombination($user_list,'id','truename');
$repair_type = $T->db->query("select id,name from sys_equipment_repair where is_flag_delete = 0")->fetchAll(PDO::FETCH_ASSOC);
$arrlist =  Recombination($repair_type,'id','name');
$list = $T->db->query($sql)->fetchAll(PDO::FETCH_ASSOC);

foreach($list AS $val){

    $statushtml1 = $statushtml2 = $statushtml3 = $statushtml4 = $statushtml5 = "";
    switch($val['status'])
    {
        case "1":
//            $statushtml4.= '<button class="layui-btn layui-btn-normal layui-btn-mini modal-iframe" id="btn_callback" data-id="'.$val['id'].'">';
//            $statushtml4.= '<i class="iconfont">&#xe653;</i>撤回';
//            $statushtml4.= '</button>';
            $statushtml2.= '<button class="layui-btn layui-btn-mini modal-iframe" data-opt="update" data-id="'.$val['id'].'">';
            $statushtml2.= '<i class="iconfont">&#xe653;</i>编辑';
            $statushtml2.= '</button>';
            $statushtml5.= '<button class="layui-btn layui-btn-primary layui-btn-mini modal-iframe" data-opt="detail" data-id="'.$val['id'].'">';
            $statushtml5.= '<i class="iconfont">&#xe653;</i>详情';
            $statushtml5.= '</button>';
            $statushtml1.= '<button class="layui-btn layui-btn-mini layui-btn-danger ajax" data-opt="del"  data-id="'.$val['id'].'">';
            $statushtml1.= '<i class="iconfont">&#xe626;</i>删除';
            $statushtml1.= '</button>';
            break;
        case "2":
            $statushtml5.= '<button class="layui-btn layui-btn-primary layui-btn-mini modal-iframe" data-opt="detail" data-id="'.$val['id'].'">';
            $statushtml5.= '<i class="iconfont">&#xe653;</i>详情';
            $statushtml5.= '</button>';
            break;
        case "3":
            $statushtml5.= '<button class="layui-btn layui-btn-primary layui-btn-mini modal-iframe" data-opt="detail" data-id="'.$val['id'].'">';
            $statushtml5.= '<i class="iconfont">&#xe653;</i>详情';
            $statushtml5.= '</button>';
            break;
        case "4":
        case "5":
        case "6":
        case "7":
            $statushtml5.= '<button class="layui-btn layui-btn-primary layui-btn-mini modal-iframe" data-opt="detail" data-id="'.$val['id'].'">';
            $statushtml5.= '<i class="iconfont">&#xe653;</i>详情';
            $statushtml5.= '</button>';
            $statushtml1.= '<button class="layui-btn layui-btn-mini layui-btn-danger ajax" data-opt="del"  data-id="'.$val['id'].'">';
            $statushtml1.= '<i class="iconfont">&#xe626;</i>删除';
            $statushtml1.= '</button>';
            break;
        case "8":

        case "9":
            $statushtml5.= '<button class="layui-btn layui-btn-primary layui-btn-mini modal-iframe" data-opt="detail" data-id="'.$val['id'].'">';
            $statushtml5.= '<i class="iconfont">&#xe653;</i>详情';
            $statushtml5.= '</button>';
            break;
        case "10":
            $statushtml5.= '<button class="layui-btn layui-btn-primary layui-btn-mini modal-iframe" data-opt="detail" data-id="'.$val['id'].'">';
            $statushtml5.= '<i class="iconfont">&#xe653;</i>详情';
            $statushtml5.= '</button>';
            break;
        default:
            $statushtml5.= '<button class="layui-btn layui-btn-primary layui-btn-mini modal-iframe" data-opt="detail" data-id="'.$val['id'].'">';
            $statushtml5.= '<i class="iconfont">&#xe653;</i>详情';
            $statushtml5.= '</button>';
            $statushtml3.= '<button class="layui-btn layui-btn-mini modal-iframe" data-opt="update" data-id="'.$val['id'].'">';
            $statushtml3.= '<i class="iconfont">&#xe653;</i>待评价';
            $statushtml3.= '</button>';
            $statushtml1.= '<button class="layui-btn layui-btn-mini layui-btn-danger ajax" data-opt="del"  data-id="'.$val['id'].'">';
            $statushtml1.= '<i class="iconfont">&#xe626;</i>删除';
            $statushtml1.= '</button>';
            break;
    }
    if($val['takes_user'] != "待指定"){
        $takes_user = $userlist[$val['takes_user']];
    }else{
        $takes_user = "待指定";
    }


    $html.="<tr>";
    //$html.= '<td><input type="checkbox" name="checkbox" lay-skin="primary" value="'.$val['id'].'"/></td>';
    $html.= '<td>'.$val['id'].'</td>';
    $html.= '<td>'.$val['service_sn'].'</td>';
    $html.= '<td>'.$arrlist[$val['takes_type']].'</td>';
    $html.= '<td>'.$val['project_type'].'</td>';
    $html.= '<td>'.$val['code'].'</td>';
    $html.= '<td>'.$val['release_time'].'</td>';
    $html.= '<td>'.$val['takes_time'].'</td>';
    $html.= '<td>'.$takes_user.'</td>';
    $html.= '<td>'.$REPAIR_STATUS[$val['status']].'</td>';
    $html.= '<td>';
    $html.= $statushtml2.$statushtml3.$statushtml5.$statushtml1;
    $html.= '</td>';
    $html.= '</tr>';
}
$T->Set("LIST_HTML",$html);
$T->Set("template",$template);
$T->clearNaN();       
$T->clearNoN();
$T->display(); 